package com.mujin.keji.collectionsystem.common;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 家用电器
 */
public enum HouseApplianceEnum {
    automatic_washing_machine("automatic_washing_machine","全自动洗衣机"),
    inch_television("29inch_television","29寸以上电视"),
    computer("computer","电脑"),
    phone("phone","电话"),
    air_conditioner("air_conditioner","空调"),
    refrigerator("refrigerator","冰箱")
    ;

    /** 状态码 **/
    private final String code;
    /** 状态描述 **/
    private final String description;

    HouseApplianceEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }


    public static String find(String origin) {
        if(StringUtils.isEmpty(origin)){
            return null;
        }
        String[] strs = origin.split(",");
        List<Integer> origins = new ArrayList<>();
        for(int i =0 ; i< strs.length;i++){
            origins.add(Integer.valueOf(strs[i]));
        }

        List<String> codes = new ArrayList<>();
        for (HouseApplianceEnum frs : HouseApplianceEnum.values()) {
            if (origins.contains(frs.ordinal()+1)) {
                codes.add(frs.code);
            }
        }

        return StringUtils.join(codes,",");
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
}
